package cn.javase.base.internet._02_TCP通讯._双向通讯;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) throws IOException {
        try(Socket client = new Socket(InetAddress.getLocalHost(), 9999);
            BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
            BufferedWriter out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
            Scanner sc = new Scanner(System.in)
        ) {
            String msg;
            while (!"exit".equals(msg = sc.nextLine())) {
                out.write(msg + "\n");
                out.flush();
                System.out.println(in.readLine());
            }
        }
    }
}
